﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="房产销冠, 房地产,卡考网络" />
    <meta name="description" content="上海卡考网络有限公司" />
    <title>活动配置</title>
    <link rel="stylesheet" href="css/list.css" type="text/css" />
    <link rel="stylesheet" href="css/global.css" type="text/css" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link href="bootstrap/iCheck-master/skins/minimal/Orange.css" rel="stylesheet" type="text/css" />
    <!--<script src="js/jquery-1.8.3.min.js"></script>-->
    <!--<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />-->
    <!--<script src="http://dn-blqw.qbox.me/jq+bs+art.js" type="text/javascript"></script>-->
    <script src="http://static.tops001.com/jq-bs-art.js" type="text/javascript"></script>
    <!--<script src="js/jquery.easydropdown.min.js"></script>-->
    <script src="bootstrap/iCheck-master/icheck.js"></script>
    <!--<script src="bootstrap/js/bootstrap.min.js"></script>-->
    <!--<script src="js/checkbox.js"></script>-->
    <script src="js/common.js"></script>
    <script src="js/PageIndex.js"></script>
    <script src="http://dn-blqw.qbox.me/kk.js"></script>
    <script src="js/WdatePicker.js"></script>
    <!--<script src="http://static.tops001.com/openSource/iDialog/1.1/jquery.iDialog.js" dialog-theme="default"></script>-->
    <script src="Scripts/jquery.iDialog.js" dialog-theme="default"></script>
    <style>
        #selbox .fromtab1 {
            margin: 20px 0 20px 30px;
        }

            #selbox .fromtab1 td, #selbox .fromtab1 th {
                line-height: 45px;
                font-size: 16px;
            }

        .from-control {
            width: 350px;
            margin: 10px 20px;
        }
    </style>
</head>
<body style="background: #f1f1f1;">
    <div class="main01">
        <div class="content clearfix">
            <div class="headline02">
                <div class="line_left">抽奖配置</div>
            </div>
            <div class="bton">
                <div class="bton_right" style="margin-top:5px;">
                    <div class="bton_left_nav">
                        <a href="newLuckSetting.html" class="btn_deal">活动设置</a>
                        <a href="#" class="btn_craise" onclick="f_clear()">活动初始化</a>
                        <a href="javascript:document.location.reload();" class="btn_refresh">刷新</a>
                    </div>
                    <div class="bton_left_nav pageIn2">
                    </div>
                </div>
            </div>
        </div>
        <div style="min-height: 500px;">
            <table class="table01" style="width: 100%; max-height: 400px; table-layout: fixed; border-bottom: 1px #e6e6e6 solid;">
                <thead>
                    <tr class="info_title">
                        <th class="mid_line">序号</th>
                        <th class="mid_line">奖品位置</th>
                        <th class="mid_line">奖品名称</th>
                        <th class="mid_line">奖品数量</th>
                        <th class="mid_line">中奖概率(%)</th>
                        <th class="mid_line">中奖提示信息</th>
                        <th class="mid_line btn_do">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="info_cont" style="display:none;">
                        <td>{F_Index}</td>
                        <td>{F_Direction}</td>
                        <td>{Name}</td>
                        <td>{Count}</td>
                        <td>{Chance}</td>
                        <td>{Description}</td>
                        <td class="btn_do">
                            <div class="reset"><a href="javascript:;" onclick="EditWindowShow('{ID}')" class="btn_revise">编辑</a></div>
                            <div class="reset"><a href="javascript:;" onclick="f_delete('{ID}')" class="btn_revise">重置</a></div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div id="selbox" class="clearfix" style="display:none">
        <table border="0" cellspacing="0" cellpadding="0" class="fromtab1">
            <tr>
                <th>奖品位置：&nbsp;</th>
                <td>
                    <span id="edit_ProductDirection" style="margin-left:50px;"></span>
                </td>
            </tr>
            <tr>
                <th>活动奖品：&nbsp;</th>
                <td>
                    <select id="F_LuckProductList" class="form-control" style="margin-right: 11px;">
                        <option value="-2" F_CategoryKid="6" >--请选择参与抽奖活动的奖品--</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th>奖品数值：&nbsp;</th>
                <td>
                    <input type="text" id="edit_ProductPoint" value="" class="form-control" placeholder="请填写奖品数值" maxlength="10" />
                </td>
            </tr>
            <tr>
                <th>奖品数量：&nbsp;</th>
                <td>
                    <input type="text" id="edit_ProductCount" value="" class="form-control" placeholder="请填写奖品数量" maxlength="10" validatetype="*arithmetic" onkeyup="value=value.replace(/[^\d]/g,'')" />
                </td>
            </tr>
            <tr>
                <th>中奖概率(%)：&nbsp;</th>
                <td>
                    <input type="text" id="edit_ProductChance" value="" class="form-control" placeholder="请填写中奖概率(%)" maxlength="5" onblur="IsDouble()" />
                </td>
            </tr>
            <tr>
                <th>中奖提示信息：&nbsp;</th>
                <td>
                    <input type="text" id="edit_ProductDescription" value="" class="form-control" placeholder="请填写中奖提示信息" maxlength="30" validatetype="*notempty" />
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="hidden" id="edit_ID" value="{ID}" />
                </td>
            </tr>
        </table>
        <div>
            <input type="button" value="确定" onclick="f_edit()" class="Save" style="margin-left:25%" />
            <input type="button" value="取消" onclick="cancel()" class="Cancel" />
        </div>

    </div>
    <script src="js/list.js"></script>
    <script type="text/javascript">
        $(function () {
            f_CheckOpenState();
            f_GetData();
            f_GetProductList();
            countwidth();
            LuckProductListChange();
        });
        var showMsgBox = null;
        function EditWindowShow(id) {
            f_GetLuckProduct(id);
            showWindows("抽奖商品编辑", "selbox", f_edit, 490, 430);
            return false;
        }

        function showWindows(title, id, func, wt, h) {
            showMsgBox = $.dialog({
                height: h,
                width: wt,
                fixed: true,
                lock: true,
                title: title,
                content: document.getElementById(id),
                init: function () {

                },
            });

        }

        function countwidth() {
            if (!$(".tab_warp").length) { return }
            var widthall = 0;
            var thall = $(".tab_warp th");
            for (var i = 0; i < thall.length; i++) {
                widthall = widthall + thall.eq(i).width();
            }
            if (widthall <= $("body").width() - 60) { widthall = $("body").width() - 60 }
            $(".main01").width(widthall);
        }

        //获取商品详细
        function f_GetData() {
            var idx = 0;
            $kk.api.get("/LuckProduct/GetList?v="+Math.random(), function (res) {
                kk.fillTable(".table01", res, function (data, name) {
                    if (name == "F_Index") {
                        idx++;
                        return idx;
                    }
                    if (name == "F_Direction") {
                        switch (idx) {
                            case 1: return "↑";
                            case 2: return "↗";
                            case 3: return "→";
                            case 4: return "↘";
                            case 5: return "↓";
                            case 6: return "↙";
                            case 7: return "←";
                            case 8: return "↖";
                        }
                    }
                    if (name == "Residue") {
                        return data["Count"] - data["LuckCount"];
                    }
                });
            });
        }

        function f_edit() {
            var edit_ProductPoint = $('#edit_ProductPoint').val();
            var edit_ProductDirection = $('#edit_ProductDirection').val();
            var edit_ProductCount = $('#edit_ProductCount').val();
            var edit_ProductChance = $('#edit_ProductChance').val();
            var edit_ProductDescription = $('#edit_ProductDescription').val();
            var edit_ID = $('#edit_ID').val();
            var productName = $('#F_LuckProductList option:selected').attr("f_productname");
            var productKid = $('#F_LuckProductList option:selected').val();
            var data = {
                Point: edit_ProductPoint,
                Count: edit_ProductCount,
                Chance: edit_ProductChance,
                Description: edit_ProductDescription,
                ID: edit_ID,
                ProductName: productName,
                ProductKid: productKid
            };
            if (data.ProductKid < 1 && data.ProductKid!=-1) {
                $kk.popup("请选择参与活动商品", "err", 3000); return;
            }
            if (data.ProductKid !=-1) {
                var selectObj = $('#F_LuckProductList option:selected');
                var F_CategoryKid = selectObj.attr("F_CategoryKid");
                if (F_CategoryKid == 4 && data.Point < 0) {
                    $kk.popup("你选择的是虚拟奖品，请填写奖励积分", "err", 3000); return;
                }
                if (data.Count < 1) {
                    $kk.popup("奖品数量不能为0", "err", 3000); return;
                }
                if (data.Chance == 0.00 || data.Chance == 0 || data.Chance == 0.0) {
                    $kk.popup("中奖概率不能为0", "err", 3000); return;
                }
                if (data.Description == '') {
                    $kk.popup("中奖提示信息不能为空", "err", 3000); return;
                }
            } else {
                data.Point = 0;
                data.Chance = 0;
                data.Count = 0;
            }
            
            $kk.api.get("/LuckProduct/Edit", data, function (res) {
                if (res == 1) {
                    f_GetData(1);
                    showMsgBox.hide();
                    $kk.popup("抽奖商品 编辑成功", "success", 3000); return;
                }
                else {
                    $kk.popup("抽奖商品 编辑失败", "err", 3000); return;
                }
            });
        }

        function cancel() {
            showMsgBox.hide();
        }

        function f_GetLuckProduct(id) {
            $kk.api.get("/LuckProduct/GetLuckProduct", { ID: id }, function (res) {

                var edit_ProductPoint = $('#edit_ProductPoint');
                var edit_ProductDirection = $('#edit_ProductDirection');
                var edit_ProductCount = $('#edit_ProductCount');
                var edit_ProductChance = $('#edit_ProductChance');
                var edit_ProductDescription = $('#edit_ProductDescription');
                var edit_ID = $('#edit_ID');
                switch (res.ID) {
                    case 1:
                        edit_ProductDirection.html("↑   正上方 12：00方向")
                        break;
                    case 8:
                        edit_ProductDirection.html("↗   右上方 1：30方向")
                        break;
                    case 7:
                        edit_ProductDirection.html("→   正右方 3：00方向")
                        break;
                    case 6:
                        edit_ProductDirection.html("↘   右下方 4：30方向")
                        break;
                    case 5:
                        edit_ProductDirection.html("↓   正下方 6：00方向")
                        break;
                    case 4:
                        edit_ProductDirection.html("↙   左下方 7：30方向")
                        break;
                    case 3:
                        edit_ProductDirection.html("←   正左方 9:00方向")
                        break;
                    case 2:
                        edit_ProductDirection.html("↖   左上方 10：30方向")
                        break;
                }
                edit_ProductPoint.val(res.Point);
                edit_ProductCount.val(res.Count);
                edit_ProductChance.val(res.Chance);
                edit_ProductDescription.val(res.Description);
                edit_ID.val(res.ID);

                if (res.Kid != 0) {
                    $('#F_LuckProductList option').each(function (index, obj) {
                        var vl = $(obj).val();
                        if (vl == res.Kid) {
                            $(obj).attr('selected', true);
                            var F_CategoryKid = $(obj).attr("F_CategoryKid");
                            if (F_CategoryKid == 6) {
                                $('#edit_ProductPoint').attr("readonly", true);
                                $('#edit_ProductCount').attr("readonly", false);
                                $('#edit_ProductChance').attr("readonly", false);
                            } else {
                                $('#edit_ProductPoint').attr("readonly", false);
                            }
                            return;
                        }
                    });
                }
                if (res.Kid == 0) {
                    $($('#F_LuckProductList option')[0]).attr('selected', true);
                    $('#edit_ProductCount').attr("readonly", false);
                    $('#edit_ProductChance').attr("readonly", false);
                    $('#edit_ProductPoint').val('');
                    $('#edit_ProductCount').val('');
                    $('#edit_ProductChance').val('');
                }
                if (res.Kid == -1) {
                    $('#edit_ProductPoint').attr("readonly", true);
                    $('#edit_ProductCount').attr("readonly", true);
                    $('#edit_ProductChance').attr("readonly", true);
                    $('#edit_ProductCount').val('无限');
                    $('#edit_ProductChance').val('自动计算');
                }
            });
        }

        function f_GetProductList() {
            var F_LuckProductList = $('#F_LuckProductList');
            $kk.api.get("/ProductShow/GetList", { cityKid: 0, categoryKid: 0, status: 0, keyWords: '', pageSize: 1000 }, function (res) {
                //console.log(res);
                $.each(res.Items, function () {
                    var html = "<option value='" + this.F_ProductKid + "' F_CategoryKid='" + this.F_CategoryKid + "' F_ProductName='" + this.F_ProductName + "'>[商品]&nbsp;&nbsp;" + this.F_ProductName + "</option>"
                    F_LuckProductList.append(html);
                });
                var thx = "<option value='-1' F_CategoryKid='4' F_ProductName='谢谢参与'>[系统]&nbsp;&nbsp;谢谢参与</option>";
                F_LuckProductList.append(thx);
            });
        }

        function LuckProductListChange() {
            $('#F_LuckProductList').change(function () {
                var selectObj = $('#F_LuckProductList option:selected');
                var F_CategoryKid = selectObj.attr("F_CategoryKid");
                console.log(F_CategoryKid);
                if (selectObj.val() == -1) {
                    $('#edit_ProductPoint').attr("readonly", true);
                    $('#edit_ProductCount').attr("readonly", true);
                    $('#edit_ProductChance').attr("readonly", true);
                    $('#edit_ProductCount').val('无限');
                    $('#edit_ProductChance').val('自动计算');
                } else {                    
                    $('#edit_ProductCount').attr("readonly", false);
                    $('#edit_ProductChance').attr("readonly", false);
                    $('#edit_ProductCount').val('');
                    $('#edit_ProductChance').val('');
                    if (F_CategoryKid == 6) {
                        $('#edit_ProductPoint').attr("readonly", true);
                        $('#edit_ProductPoint').val(0);
                    } else {
                        $('#edit_ProductPoint').attr("readonly", false);
                    }
                }
            })
        }

        function IsDouble() {
            var str = $('#edit_ProductChance').val().trim();
            if (str.length != 0) {
                reg = /^[0-9]+([.]{1}[0-9]{1,2})?$/;
                if (!reg.test(str) || str > 100) {
                    //alert("对不起，您输入的双精度类型格式不正确!");//请将“双精度类型”要换成你要验证的那个属性名称！
                    $kk.popup("中奖概率应为 0.00(%)~100.00(%) 之间的小数 如12.34", "err", 5000);
                    $('#edit_ProductChance').val('');
                }
                return;
            }
        }

        function f_delete(id) {
            $kk.api.get("/LuckProduct/Delete", { ID: id }, function (res) {
                if (res == 1) {
                    f_GetData(1);
                }
                else {
                    $kk.popup("删除失败", "err", 3000); return;
                }
            });
        }

        function f_clear() {
            $kk.api.get("/LuckProduct/Clear", {}, function (res) {
                if (res >= 1) {                   
                    document.location.reload();
                }
                else {
                    $kk.popup("删除失败", "err", 3000); return;
                }
            });
        }

        function f_CheckOpenState() {
            kk.api.get("/LuckBigTurntable/LuckActivityGet", {}, function (res) {
                if (res.isOpen == 1) {
                    $('.btn_do').hide();
                }
            });
        }
    </script>
</body>
</html>
